#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct stu
{
    int xh;
    char name[20];
    double score;
};
int main()
{
    int n,a;
    char c[20];
    double t;
    while(scanf("%d",&n)!=EOF)
    {
        struct stu s[200];
        for(int i=0;i<n;i++)
        {
            scanf("%d %s %lf",&s[i].xh,s[i].name,&s[i].score);
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n-i-1;j++)
            {
                if(s[j].score<s[j+1].score)
                {
                    t=s[j].score;
                    s[j].score=s[j+1].score;
                    s[j+1].score=t;
                    strcpy(c,s[j].name);
                    strcpy(s[j].name,s[j+1].name);
                    strcpy(s[j+1].name,c);
                    a=s[j].xh;
                    s[j].xh=s[j+1].xh;
                    s[j+1].xh=a;
                }
            }
        }
        for(int i=0;i<3;i++)
        {
            printf("%d %s\n",s[i].xh,s[i].name);
        }
    }
    return 0;
}
